package com.xiaomai.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaomai.commonutil.R;
import com.xiaomai.eduservice.entity.EduCourse;
import com.xiaomai.eduservice.entity.EduTeacher;
import com.xiaomai.eduservice.service.EduCourseService;
import com.xiaomai.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")

public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    //查询前八个热门课程/=
    @GetMapping("hot")
    public R getHot(){
        //查询前8条热门课程
        QueryWrapper<EduCourse> coursewrapper = new QueryWrapper<>();
        coursewrapper.orderByDesc("gmt_create");
        coursewrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(coursewrapper);
        //查询前4个热门讲师
        QueryWrapper<EduTeacher> teacherwrapper = new QueryWrapper<>();
        teacherwrapper.orderByDesc("gmt_create");
        teacherwrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherwrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);

    }

}
